package com.business.web.spring;


import java.util.List;
import org.apache.log4j.Logger;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//import com.workflow.WorkFlowUtils;
import com.common.db.JsonVO;
import com.common.db.Pg;
import com.common.utils.BeanUtils;
import com.business.domain.T_task_instance;
//import com.business.mapper.T_task_instanceMapper;
import com.business.service.T_task_instanceService;

@Controller
@RequestMapping("/t_task_instance")

public class T_task_instanceController
{
	private static Logger log = Logger.getLogger(T_task_instanceController.class.getName());

	@Resource
    private T_task_instanceService t_task_instanceService;

	//@Autowired
	//private WorkFlowUtils workFlowUtils;

	//@Resource
	//private T_task_instanceMapper mapper;
	//private int id;
	//private int[] ids;
	private Pg pg;

	/**
	 * 1、获取 T_task_instance信息列表，并且在列表页面展示
	 * @param request
	 * @return Pg，json格式
	 */
	@RequestMapping("/getAllT_task_instance")
	@ResponseBody
	public Pg getAllT_task_instance(HttpServletRequest request){
        int pageSize = 10;
        int startIndex = 0;
        T_task_instance t_task_instance = new T_task_instance();
        try{
	        if(request.getParameter("pageSize")!=null){
	        	pageSize = BeanUtils.stringToInt("pageSizeFlag", request.getParameter("pageSize"));
	        }
	        if(request.getParameter("startIndex")!=null){
	            startIndex = BeanUtils.stringToInt("startIndexFlag", request.getParameter("startIndex"));
	        }
	        if(request.getParameter("process_code")!=null){ //取得动作流 流程英文名称，后台查询数据关联使用
	        	t_task_instance.setProcess_code(request.getParameter("process_code"));
	        }
			if(request.getParameter("biztype")!=null&&!"".equals(request.getParameter("biztype"))){ //取得动作流 流程英文名称，后台查询数据关联使用
				t_task_instance.setBiztype(request.getParameter("biztype"));
			}
			if(request.getParameter("taskname")!=null&&!"".equals(request.getParameter("taskname"))){
	        	t_task_instance.setTaskname(request.getParameter("taskname"));
	        }
			if(request.getParameter("instancestatus")!=null&&!"".equals(request.getParameter("instancestatus"))){
	        	t_task_instance.setInstancestatus(request.getParameter("instancestatus"));
	        }
			if(request.getParameter("creater")!=null&&!"".equals(request.getParameter("creater"))){
	        	t_task_instance.setCreater(request.getParameter("creater"));
	        }
			if(request.getParameter("creatertime")!=null&&!"".equals(request.getParameter("creatertime"))){
	        	t_task_instance.setCreatertime(request.getParameter("creatertime"));
	        }
			if(request.getParameter("updater")!=null&&!"".equals(request.getParameter("updater"))){
	        	t_task_instance.setUpdater(request.getParameter("updater"));
	        }
			if(request.getParameter("updatetime")!=null&&!"".equals(request.getParameter("updatetime"))){
	        	t_task_instance.setUpdatetime(request.getParameter("updatetime"));
	        }
			if(request.getParameter("ext1")!=null&&!"".equals(request.getParameter("ext1"))){
	        	t_task_instance.setExt1(request.getParameter("ext1"));
	        }
			if(request.getParameter("ext2")!=null&&!"".equals(request.getParameter("ext2"))){
	        	t_task_instance.setExt2(request.getParameter("ext2"));
	        }
			if(request.getParameter("ext3")!=null&&!"".equals(request.getParameter("ext3"))){
	        	t_task_instance.setExt3(request.getParameter("ext3"));
	        }
			if(request.getParameter("ext4")!=null&&!"".equals(request.getParameter("ext4"))){
	        	t_task_instance.setExt4(request.getParameter("ext4"));
	        }
      	    if(request.getParameter("instanceid")!=null&&!"".equals(request.getParameter("instanceid"))){
	        	t_task_instance.setInstanceid(new Integer(request.getParameter("instanceid")));
	        }

	        if(request.getParameter("startdate")!=null&&!"".equals(request.getParameter("startdate"))){
	        	t_task_instance.setStartdate(request.getParameter("startdate"));
	        }
	        if(request.getParameter("enddate")!=null&&!"".equals(request.getParameter("enddate"))){
	        	t_task_instance.setEnddate(request.getParameter("enddate"));
	        }
	        t_task_instance.setStartNo( startIndex );
	        t_task_instance.setPageSize( pageSize );
	        t_task_instance.setEndNo( pageSize );
	    	List<T_task_instance> findAll = t_task_instanceService.findAll(t_task_instance);
	        int totalCount = t_task_instanceService.findCountAll(t_task_instance);
	       	pg = new Pg(findAll, totalCount, pageSize, startIndex);
	       	request.setAttribute("t_task_instanceList", findAll);
		    request.setAttribute("pg", pg);
	    } catch (Exception e) {
			e.printStackTrace();
			log.error("------query t_task_instanceList error:"+e);
		}

		return pg;
	}

	/**
	 * 2、新增保存  T_task_instance信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_task_instance
	 * @param request
	 * @return
	 */
	@RequestMapping("/saveT_task_instance")
	@ResponseBody
	public JsonVO saveT_task_instance(T_task_instance t_task_instance, HttpServletRequest request,HttpServletResponse response){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊需求，需要将json对象值转成java实体对象属性值
		if(t_task_instanceService.save(t_task_instance)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 3、修改T_task_instance信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_task_instance
	 * @param request
	 * @return JsonVO
	 */
	@RequestMapping("/updateT_task_instance")
	@ResponseBody
	public JsonVO updateT_task_instance(T_task_instance t_task_instance, HttpServletRequest request){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊值需要处理，在此处手工转换
		//T_task_instance t_task_instanceTemp = t_task_instanceService.findById(t_task_instance);
		//t_task_instanceTemp.setXXX(t_task_instance.getXXX());
		//if(t_task_instanceService.update(t_task_instanceTemp)){

		if(t_task_instanceService.update(t_task_instance)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 4、根据id查询T_task_instance单个信息并显示在修改页面
	 * @param id
	 * @param request
	 * @return T_task_instance json格式字符串
	 */
	@RequestMapping("/getT_task_instance")
	@ResponseBody
	public T_task_instance getT_task_instance(Integer id,HttpServletRequest request){
		T_task_instance t_task_instance = new T_task_instance();
		t_task_instance.setInstanceid(id);
		return t_task_instanceService.findById(t_task_instance);
	}

	/**
	 * 5、删除T_task_instance根据id
	 * @param id
	 * @param request
	 * @param response
	 * return JsonVO ：json格式字符串
	 */
	@RequestMapping("/delT_task_instance")
	@ResponseBody
	public JsonVO delT_task_instance(Integer id,HttpServletRequest request,HttpServletResponse response){
        JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);

		T_task_instance t_task_instance = new T_task_instance();
		t_task_instance.setInstanceid(id);

		if(t_task_instanceService.delete(t_task_instance)>0){
			vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 6、跳转到t_task_instance/toT_task_instanceList查询所有数据页面
	 *  return /WEB-INF/views/business/t_task_instance/t_task_instanceList.jsp
	 */
    @RequestMapping(value = "/toT_task_instanceList")
    public String toT_task_instanceList() {
    	log.debug("------跳转到/WEB-INF/views/business/t_task_instance/t_task_instanceList.jsp------");
        return "business/t_task_instance/t_task_instanceList";
    }

	/**
	 * 7、新增、修改、详情页面t_task_instance/toT_task_instanceCurd跳转
     * business/t_task_instance/T_task_instanceCurd.jsp
	 */
    @RequestMapping(value = "/toT_task_instanceCurd")
    public String toT_task_instanceCurd() {
    	log.debug("------跳转到/WEB-INF/views/business/t_task_instance/t_task_instanceCurd.jsp------");
        return "business/t_task_instance/t_task_instanceCurd";
    }

    /**
	 * 8、批量删除T_task_instance根据主键id
	 * 是否要实现批量删除，待考虑，基本上用途不大
	 * @param id
	 * @param request
	 * @param response
	@RequestMapping("/delT_task_instanceBatch")
	public String delT_task_instanceBatch(HttpServletRequest request,HttpServletResponse response){
		String[] ids = request.getParameterValues("ids");
		System.out.println("------ids="+ids);
		T_task_instance t_task_instance = new T_task_instance();
		int j=0;
		for(int i =0;i< ids.length;i++){
			j++;
			log.error("------ids[i]="+ids[i]);
			t_task_instance.setInstanceid(new Integer(ids[i]).intValue());
			t_task_instanceService.delete(t_task_instance);
		}
		if(j==ids.length){
			log.debug("------t_task_instance批量删除成功！------");
		}else{
			log.error("------t_task_instance批量删除部分成功！部分失败！------");
		}

		return "redirect:/t_task_instance/getAllT_task_instance";
	}
*/



}









